package com.imooc.controller;

import com.imooc.utils.IMOOCJSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@RestController
@RequestMapping("redis")
public class TestRedisController {

    @Autowired
    private StringRedisTemplate redisTemplate;

    @GetMapping("set")
    public IMOOCJSONResult set(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        return IMOOCJSONResult.ok();
    }

    @GetMapping("get")
    public IMOOCJSONResult get(String key) {
        Object result = redisTemplate.opsForValue().get(key);
        return IMOOCJSONResult.ok(result);
    }

    @GetMapping("del")
    public IMOOCJSONResult del(String key) {
        Boolean result = redisTemplate.delete(key);
        return IMOOCJSONResult.ok(result);
    }

}
